<?php
/**
 * 商品分类模型
 * @author Max.Yu <max@jipu.com>
 */

namespace Home\Model;

use Think\Model;

class ItemLabelModel extends Model{

    public function getLabel($id = 0){
        if(!$id){
            return false;
        }
        //根据传递过来的id查询判断商品分类的二级分类（商品标签绑定到二级分类）
        //$firstCategory = 0;
        $where['id'] = $id;
        $pid = D('ItemCategory')->where($where)->field('pid')->find();
        if($pid['pid'] == 0){
            //一级分类
            return false;
            //$firstCategory = $id;
        }else{
            //再往上查询一级，如还有上级  则是三级分类， 反之   二级分类
            $status = D('ItemCategory')->where("id='{$pid['pid']}'")->field('pid')->find();
            if($status['pid'] == 0){
                //二级分类
                $firstCategory = $id;
            }else{
                $firstCategory = $pid['pid'];
            }
            //return $firstCategory;
        }
        //return $firstCategory;
        //查询分类下的标签
        $label = $this->where("cid='{$firstCategory}'")->select();
        foreach($label as $key => $val){
            $label[$key]['itm_id'] = $id;
        }
        return $label;
    }

}
